cmake_minimum_required(VERSION 3.5)
project(eventloop_demo CXX)

include(CheckIncludeFileCXX)

check_include_file_cxx(any HAS_ANY)
check_include_file_cxx(string_view HAS_STRING_VIEW)
check_include_file_cxx(coroutine HAS_COROUTINE)
if (NOT "${CMAKE_CXX_STANDARD}" STREQUAL "")
    # Do nothing
elseif (HAS_ANY AND HAS_STRING_VIEW AND HAS_COROUTINE)
    set(CMAKE_CXX_STANDARD 20)
elseif (HAS_ANY AND HAS_STRING_VIEW)
    set(CMAKE_CXX_STANDARD 17)
else ()
    set(CMAKE_CXX_STANDARD 14)
endif ()

if (CMAKE_CXX_STANDARD LESS 17)
    message(FATAL_ERROR "c++17 or higher is required")
elseif (CMAKE_CXX_STANDARD LESS 20)
    message(STATUS "use c++17")
else ()
    message(STATUS "use c++20")
endif ()

set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

add_executable(${PROJECT_NAME} main.cpp)

#target_link_libraries(${PROJECT_NAME} pthread)

aux_source_directory(core/utils CORE_UTILS_SRC)
aux_source_directory(core/poller CORE_POLLER_SRC)
aux_source_directory(core CORE_SRC)

target_sources(${PROJECT_NAME}
               PRIVATE
               ${CORE_POLLER_SRC}
               ${CORE_UTILS_SRC}
               ${CORE_SRC}
)

# 设置Boost库的路径
set(BOOST_ROOT /opt/boost_1.80.0)

# 查找Boost库的组件
# find_package(Boost REQUIRED COMPONENTS context)
find_package(Boost REQUIRED COMPONENTS filesystem coroutine)

if(NOT Boost_FOUND)
    message(FATAL_ERROR "====Boost 不存在====")
else() 
    message(STATUS "====Boost 存在====")
    message(STATUS "Boost_INCLUDE_DIRS:${Boost_INCLUDE_DIRS}")
    message(STATUS "Boost_LIBRARIES:${Boost_LIBRARIES}")
    message(STATUS "Boost_LIBRARIES_DIRS:${Boost_LIBRARIES_DIRS}")
endif()

# 添加Boost库的头文件路径
include_directories(${Boost_INCLUDE_DIRS})

# 添加Boost库的链接路径
link_directories(${Boost_LIBRARY_DIRS})

# 添加Boost库的链接选项
target_link_libraries(${PROJECT_NAME} PRIVATE ${Boost_LIBRARIES} pthread)